package com.gcq.javawork.controller;

import com.gcq.javawork.common.Result;
import com.gcq.javawork.constatnts.BaseMessage;
import com.gcq.javawork.constatnts.ShoppingCartConstants;
import com.gcq.javawork.model.domain.ShoppingCart;
import com.gcq.javawork.service.ShoppingCartService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {

    @Resource
    private ShoppingCartService shoppingCartService;

    /**
     *购物车查询
     * @param id
     * @return
     */
    public Result<List<ShoppingCart>> getShoppingCart(@PathVariable("userId") long id) {
        if (id <= 0){
            return Result.fail(BaseMessage.User_ID_CANT_NOT_NULL);
        }
        List<ShoppingCart> shoppingCartByUserId = shoppingCartService.getShoppingCartByUserId(id);
        return Result.success(shoppingCartByUserId);
    }
}
